package com.json.dao.impl;

import com.json.dao.StudentDAO;
import com.json.entity.Student;
import com.json.util.JDBCUtils;

import java.util.List;

/**
 * 学生数据访问实现类
 */
public class StudentDAOImpl implements StudentDAO {
    @Override
    public List<Student> selectAllStudents() {
        return JDBCUtils.query(Student.class,"select * from student");
    }
    @Override
    public List<Student> selectByKeyWord(String keyword){
        return JDBCUtils.query(Student.class,"select * from student where name like ?","%"+keyword+"%");
    }
    @Override
    public List<Student> selectById(Integer id){
        return JDBCUtils.query(Student.class,"select * from student where id = ?",id);
    }
    @Override
    public boolean insert(String name,Integer age,String cellphone,String address,String gender){
        if (JDBCUtils.update("insert into student(name,age,cellphone,address,gender) values(?,?,?,?,?)",name,age,cellphone,address,gender)>0){
            return true;
        }
        else {
            return false;
        }
    }
    @Override
    public boolean update(String name,Integer age,String cellphone,String address,String gender,Integer id){
        if (JDBCUtils.update("update student set name=?,age=?,cellphone=?,address=?,gender=? where id=?",name,age,cellphone,address,gender,id)>0){
            return true;
        }
        else {
            return false;
        }
    }
    @Override
    public boolean delete(Integer id){
        if (JDBCUtils.update("delete from student where id=?",id)>0){
            return true;
        }
        else {
            return false;
        }
    }
}
